<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ page import="org.springframework.context.ApplicationContext" %>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ page import="org.jwos.platform.domain.*" %>
<%@ page import="org.jwos.platform.service.PluginManager" %>
<%@ page import="org.jwos.platform.service.SessionManager" %>
<%@ page import="org.jwos.platform.domain.Plugin" %>
<%@ page import="org.jwos.platform.domain.PluginResource" %>
<%
boolean isAdmin = false;
String sessionId = request.getSession().getId();
ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
SessionManager sessionManager = (SessionManager)context.getBean("sessionManager");
User user = sessionManager.getUserBySessionId(sessionId);
if(user==null) {
	response.sendRedirect("login/login.jsp");
	return;
} else {
	isAdmin = user.getUserId().equals("admin");
}

PluginManager pluginManager = (PluginManager)context.getBean("pluginManager");
List<Plugin> systemPlugins = pluginManager.getSystemPlugins();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>JWOS Desktop</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    
<!-- EXT -->
<script type="text/javascript" src="ext/ext-core.js"></script> 
<script type="text/javascript" src="ext/ext-all.js"></script>
<script type="text/javascript" src="ext/source/locale/ext-lang-<%=user.getLocale()%>.js"></script>
<link rel="stylesheet" type="text/css" href="ext/resources/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="ext/resources/css/xtheme-gray.css" />
    
<!-- DESKTOP -->
<script type="text/javascript" src="js/desktop/StartMenu.js"></script>
<script type="text/javascript" src="js/desktop/TaskBar.js"></script>
<script type="text/javascript" src="js/desktop/Desktop.js"></script>
<script type="text/javascript" src="js/desktop/App.js"></script>
<script type="text/javascript" src="js/desktop/Module.js"></script>
<link rel="stylesheet" type="text/css" href="style/desktop.css" />

<!-- COMMON -->
<script type="text/javascript" src="js/common/Common.js"></script>
    
<%
for(int i=0;i<systemPlugins.size();i++) {
	Plugin plugin = systemPlugins.get(i);
	out.println("<!-- PLUGIN: "+plugin.getName()+" BEGIN -->");
	
	PluginResource localeResource = plugin.getLocaleResource(user.getLocale());
	if(localeResource!=null) {
		out.println("<script type=\"text/javascript\" src=\"../"+plugin.getPath()+"/"+localeResource.getPathWithVersion()+"\"></script>");
	}
	
	List<PluginResource> resources = plugin.getResources();
	for(int j=0;j<resources.size();j++) {
		PluginResource resource = resources.get(j);
		if(resource.getType()==PluginResource.TYPE_SCRIPT) {
			out.println("<script type=\"text/javascript\" src=\"../"+plugin.getPath()+"/"+resource.getPathWithVersion()+"\"></script>");
		} else if(resource.getType()==PluginResource.TYPE_STYLE) {
			out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"../"+plugin.getPath()+"/"+resource.getPathWithVersion()+"\" />");
		}
	}
	out.println("<!-- PLUGIN: "+plugin.getName()+" END  -->");
}
%>

<%
if(isAdmin) {
%>
<!-- PLUGIN: UserManager -->
<script type="text/javascript" src="js/system/user/UserManager.UserManager.js"></script>
<script type="text/javascript" src="js/system/user/Module.js"></script>
<link rel="stylesheet" type="text/css" href="style/usermanager.css" />
<%
}
%>

<!-- APPLICATION -->
<script type="text/javascript" src="js/desktop/locale/Desktop.Messages_<%=user.getLocale()%>.js"></script>
<script type="text/javascript" src="js/MyDesktop.js"></script>
<script type="text/javascript">
	MyDesktop.currentSessionId = '<%=session.getId()%>';
</script>

</head>
<body>

<div id="x-desktop">
</div>

<div id="ux-taskbar">
	<div id="ux-taskbar-start"></div>
	<div id="ux-taskbuttons-panel"></div>
	<div id="ux-taskbar-notify"></div>

	<div class="x-clear"></div>
</div>
    
</body>
</html>